package com.yonyou.gmmc.service.wechatpush.event.handler;

import java.util.HashMap;
import java.util.Map;

import org.apache.log4j.Logger;
import org.marketing.common.dto.EventDataDTO;
import org.springframework.beans.factory.annotation.Autowired;

import com.yonyou.gmmc.service.wechatpush.event.exception.PushException;
import com.yonyou.gmmc.service.wechatpush.service.TokenService;
import com.yonyou.gmmc.service.wechatpush.service.WechatLocalPublishService;
import com.yonyou.gmmc.service.wechatpush.util.SpringUtil;

public class MassSendEventHandler extends AbstractEventHandle{
    private static Logger logger=Logger.getLogger(MassSendEventHandler.class);

    @Autowired
    private WechatLocalPublishService wechatLocalPublishService;
    @Autowired
    private TokenService tokenService;
    private void init(){
    	tokenService=(TokenService)SpringUtil.getBean("tokenService");
    	wechatLocalPublishService=(WechatLocalPublishService)SpringUtil.getBean("wechatLocalPublishService");
    }
	@Override
	protected boolean push(EventDataDTO eventData) throws PushException{
		init();
        logger.info("newsInformationSend in");
        Map<String ,Object> resultMap ;
        try {
            String accessToken = tokenService.getAccessToken();
            resultMap = wechatLocalPublishService.treatWechatMessages( accessToken);

        } catch(Exception e) {
        	logger.error(e.getMessage(), e);
            resultMap = new HashMap<String , Object>();
            resultMap.put("STATUS", "0");
            resultMap.put("MESSAGE", e.getMessage());
        }
        return true;
	}

}
